<!DOCTYPE html>
<html lang="zh-cn">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>JS012-用户协议倒计时案例</title>
</head>

<body>
  <textarea name="" id="" cols="20" rows="10">
    用户协议
  </textarea>
  <button class="agree-btn" disabled>同意用户协议 (s)</button>
  <script>
    const agreeBtn = document.querySelector('.agree-btn')
    let agreeTimer = 5
    agreeBtn.innerHTML = `同意用户协议 (${agreeTimer}s)`
    let agreeTimerId = setInterval((function () {
      agreeTimer--
      agreeBtn.innerHTML = `同意用户协议 (${agreeTimer}s)`
      if (agreeTimer <= 0) {
        agreeBtn.disabled = false
        agreeBtn.innerHTML = '同意用户协议'
        clearInterval(agreeTimerId)
      }
    }), 1000)
  </script>
</body>

</html>